package com.web.dao;

import com.web.entity.KftApply;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface KftApplyMapper {
    @Delete({
            "delete from t_kft_apply",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_kft_apply (m_id, name,",
            " phone, merchant_name, ",
            " id_card_hold,bank_open, bank_card_front, ",
            " bank_card_back, store_front, ",
            " status, reason, id_valid_date, licence_valid_date, kft_id, ",
            " create_time, modify_time)",
            " values (#{mId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
            " #{phone,jdbcType=VARCHAR}, #{merchantName,jdbcType=VARCHAR}, ",
            " #{idCardHold,jdbcType=VARCHAR},#{bankOpen,jdbcType=VARCHAR}, #{bankCardFront,jdbcType=VARCHAR}, ",
            " #{bankCardBack,jdbcType=VARCHAR}, #{storeFront,jdbcType=VARCHAR}, ",
            " #{status,jdbcType=TINYINT}, #{reason,jdbcType=VARCHAR}, #{idValidDate,jdbcType=VARCHAR}, #{licenceValidDate,jdbcType=VARCHAR}, #{kftId,jdbcType=VARCHAR}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(KftApply record);

    @InsertProvider(type = KftApplySqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(KftApply record);

    @Select({
            "select ",
            " id, m_id, name, phone, merchant_name,id_card_hold, bank_open, bank_card_front, bank_card_back, ",
            " store_front, status, reason, create_time, modify_time, id_valid_date, licence_valid_date, kft_id ",
            " from t_kft_apply ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "merchant_name", property = "merchantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "id_card_hold", property = "idCardHold", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_open", property = "bankOpen", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_card_front", property = "bankCardFront", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_card_back", property = "bankCardBack", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_front", property = "storeFront", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "id_valid_date", property = "idValidDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_valid_date", property = "licenceValidDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "kft_id", property = "kftId", jdbcType = JdbcType.VARCHAR)
    })
    KftApply selectByPrimaryKey(Long id);

    @UpdateProvider(type = KftApplySqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(KftApply record);

    @Update({
            "update t_kft_apply",
            " set m_id = #{mId,jdbcType=BIGINT},",
            " name = #{name,jdbcType=VARCHAR},",
            " phone = #{phone,jdbcType=VARCHAR},",
            " merchant_name = #{merchantName,jdbcType=VARCHAR},",
            " bank_open = #{bankOpen,jdbcType=VARCHAR},",
            " id_card_hold = #{idCardHold,jdbcType=VARCHAR},",
            " bank_card_front = #{bankCardFront,jdbcType=VARCHAR},",
            " bank_card_back = #{bankCardBack,jdbcType=VARCHAR},",
            " store_front = #{storeFront,jdbcType=VARCHAR},",
            " status = #{status,jdbcType=TINYINT},",
            " reason = #{reason,jdbcType=VARCHAR},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP},",
            " id_valid_date = #{idValidDate,jdbcType=VARCHAR},",
            " licence_valid_date = #{licenceValidDate,jdbcType=VARCHAR},",
            " kft_id = #{kftId,jdbcType=VARCHAR} ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(KftApply record);

    @Select({
            "select ",
            " id, m_id, name, phone, merchant_name, id_card_hold,bank_open, bank_card_front, bank_card_back, ",
            " store_front, status, reason, create_time, modify_time, id_valid_date, licence_valid_date, kft_id ",
            " from t_kft_apply ",
            " where m_id = #{mId,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "merchant_name", property = "merchantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "id_card_hold", property = "idCardHold", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_open", property = "bankOpen", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_card_front", property = "bankCardFront", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_card_back", property = "bankCardBack", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_front", property = "storeFront", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "id_valid_date", property = "idValidDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_valid_date", property = "licenceValidDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "kft_id", property = "kftId", jdbcType = JdbcType.VARCHAR)
    })
    KftApply findByMid(@Param("mId") Long mId);

    @Select({
            "select ",
            " id, m_id, name, phone, merchant_name, id_card_hold,bank_open, bank_card_front, bank_card_back, ",
            " store_front, status, reason, create_time, modify_time, id_valid_date, licence_valid_date, kft_id ",
            " from t_kft_apply ",
            " where status=4 limit 100"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "merchant_name", property = "merchantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "id_card_hold", property = "idCardHold", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_open", property = "bankOpen", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_card_front", property = "bankCardFront", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_card_back", property = "bankCardBack", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_front", property = "storeFront", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "id_valid_date", property = "idValidDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_valid_date", property = "licenceValidDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "kft_id", property = "kftId", jdbcType = JdbcType.VARCHAR)
    })
    List<KftApply> selectNeedQueryRecord();
}